﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using DataAccess;
using Model.EntityModel;

namespace Project
{
    /// <summary>
    /// Interaction logic for PrintComplaint.xaml
    /// </summary>
    public partial class PrintComplaint : UserControl
    {
        private long ComplaintId;
        public PrintComplaint(long complaintId)
        {
            ComplaintId = complaintId;
            InitializeComponent();
            lblCaseNumber.Content = ComplaintId;
            SetComplainantInfo();
            SetAggressorInfo();
            SetVictimInfo();
            SetComplaintInfo();
        }

        private void SetComplainantInfo()
        {
            Actor actorComplainant = PersonAndActorDataAccess.GetActorByTypeAndComplaintId("Denunciante", ComplaintId);
            var personComplainant = PersonAndActorDataAccess.GetPersonById(actorComplainant.IdPerson);
            tbCompName.Content = personComplainant.Name;
            tbCompLastName.Content = personComplainant.PaternalName;
            tbCompMiddleName.Content = personComplainant.MaternalName;
            CompBornDate.Content = personComplainant.BirthDate.Value.ToShortDateString();
            lblCompGender.Content = (personComplainant.Gender[0] == 'M') ? "Varón" : "Mujer";
            tbCompCI.Content = personComplainant.CiPassport.ToString();
            tbCompPhone.Content = personComplainant.Phone;
            cbCompCivilStatus.Content = personComplainant.CivilStatus;
            tbCompAddress.Content = personComplainant.Address;
            cboxCompCountry.Content = personComplainant.Nationality;
            tbCompZone.Content = personComplainant.Zone;
            tbOcc.Content = personComplainant.Ocupation;
        }

        private void SetAggressorInfo()
        {
            Actor actorAggressor = PersonAndActorDataAccess.GetActorByTypeAndComplaintId("Agresor", ComplaintId);
            var personAggressor = PersonAndActorDataAccess.GetPersonById(actorAggressor.IdPerson);
            tbAggressorCi.Content = personAggressor.CiPassport.ToString();
            tbAggressorName.Content = personAggressor.Name;
            tbAggressorLastName.Content = personAggressor.PaternalName;
            tbAggressorMiddleName.Content = personAggressor.MaternalName;
            AggressorBornDate.Content = personAggressor.BirthDate.Value.ToShortDateString();
            lblAggressorGender.Content = (personAggressor.Gender[0] == 'M') ? "Varón" : "Mujer";
            tbAggressorPhone.Content = personAggressor.Phone;
            cbAggressorCivilStatus.Content = personAggressor.CivilStatus;
            cbAggressorCountry.Content = personAggressor.Nationality;
            tbAggressorBornPlace.Content = personAggressor.BornCity + " (Area " + personAggressor.BornArea + ")";
            cbAggressorInstructionLevel.Content = personAggressor.LevelOfEducation;
            lblAggressorActivityCond.Content = personAggressor.ActivityStatus;
        }

        private void SetVictimInfo()
        {
            Actor actorVictim = PersonAndActorDataAccess.GetActorByTypeAndComplaintId("Victima", ComplaintId);
            var personVictim = PersonAndActorDataAccess.GetPersonById(actorVictim.IdPerson);
            tbVictimName.Content = personVictim.Name;
            tbVictimLastName.Content = personVictim.PaternalName;
            tbVictimMiddleName.Content = personVictim.MaternalName;
            VictimBornDate.Content = personVictim.BirthDate.Value.ToShortDateString();
            lblVictimGender.Content = (personVictim.Gender[0] == 'M') ? "Varón" : "Mujer";
            tbVictimCI.Content = personVictim.CiPassport.ToString();
            tbVictimPhone.Content = personVictim.Phone;
            cbVictimCivilStatus.Content = personVictim.CivilStatus;
            tbVictimBornPlace.Content = personVictim.BornCity + " (Area " + personVictim.BornArea + ")";
            cbVictimCountry.Content = personVictim.Nationality;
            cbVictimInstructionLevel.Content = personVictim.LevelOfEducation;
            lblVictimActivityCond.Content = personVictim.ActivityStatus;
        }

        private void SetComplaintInfo()
        {
            var complaint = ComplaintDataAccess.GetComplaintById(ComplaintId);
            lblCaseDate.Content = complaint.RegistrationDate.ToShortDateString();
            cboxCompPartnership.Content = complaint.ComplainantVictimRelationship;
            cboxVictimPartnership.Content = complaint.VictimAgressorRelationship;
            lblAggressorTemp.Content = complaint.ConductOfAgressor;
        }
    }
}
